<?php

namespace Biz\model\FineGoodsBrokeNews;

use Doraemon\pockets\cache\Redis;

class FineGoodsBrokeNewsLogModel extends \Doraemon\pockets\datebase\BaseDbModel
{
    public const _CONFIG_FILE_ = 'db_store';

    public const _CONFIG_SELECT_ = 'db_brand_activity';

    public const _DATABASE_ = 'brand_activity';

    public const _TABLE_NAME = 'fine_goods_broke_news_log';

    /** @var string 日志类型：好物爆料 */
    public const DATA_TYPE_BROKE_NEWS = "0";

    /** @var string 日志类型：晒好物 */
    public const DATA_TYPE_NOTE = "1";

    public const PAGE_LIMIT = "20";

    /** @var int 数据状态正常 */
    public const DATA_ACTIVE = 0;

    /** @var int 数据状态已删除 */
    public const DATA_DELETED = 1;

    /**
     * 获取所有参加活动的日志
     * @return array|bool
     */
    public static function getLogs()
    {
        return self::select(['uid', 'data_type'], [
            "ORDER" => ['id' => "DESC"],
            'LIMIT' => self::PAGE_LIMIT
        ]);
    }

    public static function getNoteLog($uidArray)
    {
        return self::select(['uid', 'obj_id'], [
            'uid' => $uidArray,
            'is_del' => self::DATA_ACTIVE,
            'data_type' => self::DATA_TYPE_NOTE,
            "ORDER" => ['id' => "DESC"],
        ]);
    }

    /**
     * 添加好物爆料日志
     * @param $uid
     * @param $objID
     * @return bool|\PDOStatement
     */
    public static function addBrokeNewsLog($uid, $objID, $fansNum)
    {
        return self::insert([
            'uid' => $uid,
            'data_type' => self::DATA_TYPE_BROKE_NEWS,
            'fan_num' => $fansNum,
            'obj_id' => $objID
        ]);
    }

    /**
     * 添加晒好物日志
     * @param $uid
     * @param $objID
     * @return bool|\PDOStatement
     */
    public static function addNoteLog($uid, $objID, $fansNum)
    {
        return self::insert([
            'uid' => $uid,
            'data_type' => self::DATA_TYPE_NOTE,
            'fan_num' => $fansNum,
            'obj_id' => $objID
        ]);
    }

    /**
     * 删除日志
     * @param $uid
     * @param $objID
     * @return bool|\PDOStatement
     */
    public static function delLog($uid, $objID)
    {
        return self::update(['is_del' => 1], ['uid' => $uid, 'obj_id' => $objID]);
    }

    /**
     * 获取所有的用户ID
     * @param string $orderBy
     * @return array|bool
     */
    public static function getUserIDList(string $orderBy)
    {
        return self::select(["uid","data_type","obj_id", "id"], [
                'is_del' => self::DATA_ACTIVE,
                'ORDER' => [$orderBy => "DESC"]
            ]) ?? [];
    }
}